package com.sh.data.engine.application.service.authority;

import com.sh.data.engine.application.model.dto.authority.RoleDTO;
import com.sh.data.engine.application.model.dto.base.PagerResponse;
import com.sh.data.engine.application.model.mapper.authority.RoleDTOMapper;
import com.sh.data.engine.application.model.mapper.authority.RoleParamMapper;
import com.sh.data.engine.application.model.request.management.ProjectRoleCreateRequest;
import com.sh.data.engine.application.model.request.management.ProjectRoleUpdateRequest;
import com.sh.data.engine.domain.authority.model.param.RoleParam;
import com.sh.data.engine.domain.authority.service.RoleService;
import com.sh.data.engine.domain.authority.service.UserProjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class RoleApplicationService {

    @Autowired
    private RoleService roleService;

    @Autowired
    private RoleDTOMapper roleDTOMapper;

    @Autowired
    private RoleParamMapper roleParamMapper;

    @Autowired
    private UserProjectService userProjectService;

    public boolean delRole(int id, Boolean execSecutityFlag) {

        return roleService.delRole(id, execSecutityFlag);
    }

    public PagerResponse<RoleDTO> list(Integer pageNum, Integer pageSize,
                                       String roleName, String roleDesc) {
        var roleList = roleService.list(pageNum, pageSize, roleName, roleDesc);
        return roleDTOMapper.toPageResponse(roleList);
    }

    public PagerResponse<RoleDTO> listSysRole(Integer pageNum, Integer pageSize,
                                              String roleName, String roleDesc) {
        var roleList = roleService.listSysRole(pageNum, pageSize, roleName, roleDesc);
        return roleDTOMapper.toPageResponse(roleList);
    }

    public List<RoleDTO> findByMenuId(Long menuId) {
        var roleList = roleService.findByMenuId(menuId);
        return roleDTOMapper.map(roleList);
    }

    public boolean addRole(RoleParam roleParam, Boolean execSecurityFlag) {
        return roleService.addRole(roleParam, execSecurityFlag);
    }

    public boolean addRole(ProjectRoleCreateRequest request, Boolean execSecurityFlag) {
        RoleParam roleParam = roleParamMapper.map(request);
        return roleService.addRole(roleParam, execSecurityFlag);
    }

    public boolean editRole(ProjectRoleUpdateRequest request, Boolean execSecurityFlag) {
        RoleParam roleParam = roleParamMapper.map(request);
        return roleService.editRole(roleParam, execSecurityFlag);
    }

    public boolean editRole(RoleParam roleParam, Boolean execSecurityFlag) {
        return roleService.editRole(roleParam, execSecurityFlag);
    }

    public RoleDTO getByIdWithMenu(Long id) {
        return roleDTOMapper.domaintoDTO(roleService.getByIdWithMenu(id));
    }

}
